

#include "zos_config.h"

#ifdef BOARD_USING_UART_DEMO
#include  "zos.h"
//串口中断回调函数
void uart1_callback(zos_uint8_t *rev_data, zos_uint16_t len)
{

	char *str_out = ZOS_NULL;
	str_out = zos_zalloc(len+50);
	sprintf(str_out, "uart1_callback revdata:%s,len:%d\r\n", rev_data,len);
	zos_printf("rev_len=%d\r\n",len);
	shell_uart_write(str_out,strlen(str_out));
	zos_free(str_out);
    //回写收到的数据
	zos_uart_write(ZOS_UART_BUS_1,rev_data,len);

}

//串口demo
int demo_uart1(int argc, char *argv[])
{
	ZOS_UART_CONFIG uart_cfg;
	if(argc < 2)
	{
		zos_printf("Usage:\r\n");
		zos_printf("demo_uart1 Baud_rate        - uart1 demo\r\n");
	}
	else
	{
		uart_cfg.baud_rate=atoi(argv[1]);
		uart_cfg.data_bits=ZOS_UART_DATA_BITS_8;
		uart_cfg.parity=ZOS_UART_PARITY_NONE;
		uart_cfg.stop_bits=ZOS_UART_STOP_BITS_1;
		return zos_uart_init(ZOS_UART_BUS_1,&uart_cfg,uart1_callback);
	}
	return ZOS_ERROR;
}

#include "shell.h"

SHELL_EXPORT_CMD(demo_uart1,demo_uart1, uart1 demo);


//串口中断回调函数
void uart2_callback(zos_uint8_t *rev_data, zos_uint16_t len)
{
	char *str_out = ZOS_NULL;
	str_out = zos_zalloc(len+50);
	sprintf(str_out,"uart2_callback revdata:%s,len:%d\r\n", rev_data,len);
	zos_printf("rev_len=%d\r\n",len);
	shell_uart_write(str_out,strlen(str_out));
	zos_free(str_out);
    //回写收到的数据
	zos_uart_write(ZOS_UART_BUS_2,rev_data,len);

}
//串口2 demo
//GPIO6 TX2
//GPIO7 RX2
void demo_uart2(int argc, char *agrv[])
{
	ZOS_UART_CONFIG uart_cfg;
	if(argc < 2)
	{
		zos_printf("Usage:\r\n");
		zos_printf("demo_uart2 Baud_rate        - uart2 demo\r\n");
	}
	else
	{
		uart_cfg.baud_rate=atoi(agrv[1]);
		uart_cfg.data_bits=ZOS_UART_DATA_BITS_8;
		uart_cfg.parity=ZOS_UART_PARITY_NONE;
		uart_cfg.stop_bits=ZOS_UART_STOP_BITS_1;
		return zos_uart_init(ZOS_UART_BUS_2,&uart_cfg,uart2_callback);
	}

}

SHELL_EXPORT_CMD(demo_uart2,demo_uart2, uart2 demo);

#endif //BOARD_USING_UART_DEMO
